#include "handler.h"
#include "buttons.h"
#include "consts.h"

extern HINSTANCE INST;

LRESULT handler::wm_create(MsgInfo info) {
  // TODO: 创建控件
  auto _btn1 =
      CreateWindow(L"button", L"点击我", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                   150, 100, 100, 30, info.window, (HMENU)IDC_BTN1, INST, NULL);
  return 0;
}

LRESULT handler::wm_command(MsgInfo info) {
  // TODO: 处理控件消息

  // 按控件ID区分处理, 比如按钮放在 buttons.h/cpp 的 buttons 命名空间中
  // id 值统一放到 consts.h 中
  if (info.id >= IDC_BTN1 && info.id <= IDC_BTN5) {
    buttons::handle_command(info);
  }
  return 0;
}

LRESULT handler::wm_paint(MsgInfo info) {
  PAINTSTRUCT ps{};
  HDC hdc = BeginPaint(info.window, &ps);
  // 这里可以进行绘制操作
  // FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1));
  DrawText(hdc, L"Hello, world!", -1, &ps.rcPaint,
           DT_SINGLELINE | DT_CENTER | DT_VCENTER);
  EndPaint(info.window, &ps);
  return 0;
}
